package top.ywlog.permission.controller;

import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.ywlog.permission.common.request.RoleParam;
import top.ywlog.permission.common.response.Result;
import top.ywlog.permission.service.SysRoleService;
import top.ywlog.permission.service.SysTreeService;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author: Durian
 * @date: 2020/10/24 20:50
 * @description:
 */
@Validated
@Controller
@RequestMapping("/sys/role")
public class SysRoleController
{
    @Resource
    private SysRoleService sysRoleService;
    @Resource
    private SysTreeService sysTreeService;

    @PostMapping("/save")
    @ResponseBody
    public Result saveRole(@RequestBody @Validated RoleParam roleParam)
    {
        sysRoleService.saveRole(roleParam);
        return Result.success();
    }

    @PutMapping("/update")
    @ResponseBody
    public Result updateRole(@RequestBody @Validated RoleParam roleParam)
    {
        sysRoleService.updateRole(roleParam);
        return Result.success();
    }

    @GetMapping("/roleTree/{roleId}")
    @ResponseBody
    public Result getRoleTree(@PathVariable @NotNull(message = "参数错误") Integer roleId)
    {
        return Result.success(sysTreeService.roleTree(roleId));
    }
}
